package com.zp.base.controller.serialNumberDict;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.zp.base.entity.serialNumberDict.bo.SerialNumberDictBo;
import com.zp.base.entity.serialNumberDict.vo.SerialNumberDictVo;
import com.zp.base.service.serialNumberDict.ISerialNumberDictService;
import com.zp.common.core.controller.BaseController;
import com.zp.common.core.entity.R;
import com.zp.common.core.validate.AddGroup;
import com.zp.common.core.validate.EditGroup;
import com.zp.common.excel.utils.ExcelUtil;
import com.zp.common.log.annotation.Log;
import com.zp.common.log.enums.BusinessType;
import com.zp.common.myBatis.core.page.PageQuery;
import com.zp.common.myBatis.core.page.TableDataInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 业务系统单号、序号字典控制器
 * 前端访问路由地址为:/serialNumberDict/serialNumberDict
 *
 * @author zhang peng
 * @ date 2023-07-07
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/serialNumberDict")
public class SerialNumberDictController extends BaseController {

    private final ISerialNumberDictService iSerialNumberDictService;

    /**
     * 查询业务系统单号、序号字典列表 (分页)
     */
    @SaCheckPermission("serialNumberDict:serialNumberDict:list")
    @GetMapping("/selectPage")
    public TableDataInfo<SerialNumberDictVo> selectPage (SerialNumberDictBo bo, PageQuery pageQuery) {
        return iSerialNumberDictService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询业务系统单号、序号字典列表 (不分页)
     */
    @SaCheckPermission("serialNumberDict:serialNumberDict:list")
    @GetMapping("/list")
    public R<List<SerialNumberDictVo>> list (SerialNumberDictBo bo) {
        List<SerialNumberDictVo> list = iSerialNumberDictService.queryList(bo);
        return R.ok(list);
    }

    /**
     * 导出业务系统单号、序号字典列表
     */
    @SaCheckPermission("serialNumberDict:serialNumberDict:export")
    @Log(title = "业务系统单号、序号字典", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export (SerialNumberDictBo bo, HttpServletResponse response) {
        List<SerialNumberDictVo> list = iSerialNumberDictService.queryList(bo);
        ExcelUtil.exportExcel(list, "业务系统单号、序号字典", SerialNumberDictVo.class, response);
    }

    /**
     * 获取业务系统单号、序号字典详细信息
     *
     * @param noId 主键
     */
    @SaCheckPermission("serialNumberDict:serialNumberDict:list")
    @GetMapping("/{noId}")
    public R<SerialNumberDictVo> getInfo (@NotNull(message = "主键不能为空") @PathVariable String noId) {
        return R.ok(iSerialNumberDictService.queryById(noId));
    }

    /**
     * 新增业务系统单号、序号字典
     */
    @SaCheckPermission("serialNumberDict:serialNumberDict:add")
    @Log(title = "业务系统单号、序号字典", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<SerialNumberDictBo> add (@Validated(AddGroup.class) @RequestBody SerialNumberDictBo bo) {
        return R.ok(iSerialNumberDictService.insertByBo(bo));
    }

    /**
     * 修改业务系统单号、序号字典
     */
    @SaCheckPermission("serialNumberDict:serialNumberDict:edit")
    @Log(title = "业务系统单号、序号字典", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<SerialNumberDictBo> edit (@Validated(EditGroup.class) @RequestBody SerialNumberDictBo bo) {
        return R.ok(iSerialNumberDictService.updateByBo(bo));
    }

    /**
     * 删除业务系统单号、序号字典
     *
     * @param noIds 主键串
     */
    @SaCheckPermission("serialNumberDict:serialNumberDict:remove")
    @Log(title = "业务系统单号、序号字典", businessType = BusinessType.DELETE)
    @DeleteMapping("/{noIds}")
    public R<Void> remove (@NotEmpty(message = "主键不能为空") @PathVariable String[] noIds) {
        return toAjax(iSerialNumberDictService.deleteWithValidByIds(Arrays.asList(noIds), true) ? 1 : 0);
    }
}
